#########################
#  Figure 1, Manuscript #
#########################
rm(list = ls());library(foreign);
install.packages("extrafont", dependencies=TRUE);library(extrafont)
install.packages("RColorBrewer", dependencies=TRUE)



a<-read.table("Tw1_4lag_95%.txt");  a1<-read.table("Tw1_4lag_90%.txt")
b<-read.table("Tw2_4lag_95%.txt");b1<-read.table("Tw2_4lag_90%.txt")
c<-read.table("Tw3_4lag_95%.txt");c1<-read.table("Tw3_4lag_90%.txt")
d<-read.table("Tw4_4lag_95%.txt");d1<-read.table("Tw4_4lag_90%.txt")
e<-read.table("TwTOT_4lag_95%.txt");e1<-read.table("TwTOT_4lag_90%.txt")

names(a)[2]<-"US_to_Gov"
names(a)[3]<-"US_to_Gov_Low"
names(a)[4]<-"US_to_Gov_High"
names(a)[5]<-"US_to_Reb"
names(a)[6]<-"US_to_Reb_Low"
names(a)[7]<-"US_to_Reb_High"

names(b)[3]<-"US_to_Gov"
names(b)[4]<-"US_to_Gov_Low"
names(b)[5]<-"US_to_Gov_High"
names(b)[7]<-"US_to_Reb"
names(b)[8]<-"US_to_Reb_Low"
names(b)[9]<-"US_to_Reb_High"

names(c)[3]<-"US_to_Gov"
names(c)[4]<-"US_to_Gov_Low"
names(c)[5]<-"US_to_Gov_High"
names(c)[7]<-"US_to_Reb"
names(c)[8]<-"US_to_Reb_Low"
names(c)[9]<-"US_to_Reb_High"

names(d)[3]<-"US_to_Gov"
names(d)[4]<-"US_to_Gov_Low"
names(d)[5]<-"US_to_Gov_High"
names(d)[7]<-"US_to_Reb"
names(d)[8]<-"US_to_Reb_Low"
names(d)[9]<-"US_to_Reb_High"

names(e)[3]<-"US_to_Gov"
names(e)[4]<-"US_to_Gov_Low"
names(e)[5]<-"US_to_Gov_High"
names(e)[7]<-"US_to_Reb"
names(e)[8]<-"US_to_Reb_Low"
names(e)[9]<-"US_to_Reb_High"

names(a1)[2]<-"US_to_Gov"
names(a1)[3]<-"US_to_Gov_Low"
names(a1)[4]<-"US_to_Gov_High"
names(a1)[5]<-"US_to_Reb"
names(a1)[6]<-"US_to_Reb_Low"
names(a1)[7]<-"US_to_Reb_High"

names(b1)[2]<-"US_to_Gov"
names(b1)[3]<-"US_to_Gov_Low"
names(b1)[4]<-"US_to_Gov_High"
names(b1)[5]<-"US_to_Reb"
names(b1)[6]<-"US_to_Reb_Low"
names(b1)[7]<-"US_to_Reb_High"

names(c1)[2]<-"US_to_Gov"
names(c1)[3]<-"US_to_Gov_Low"
names(c1)[4]<-"US_to_Gov_High"
names(c1)[5]<-"US_to_Reb"
names(c1)[6]<-"US_to_Reb_Low"
names(c1)[7]<-"US_to_Reb_High"

names(d1)[2]<-"US_to_Gov"
names(d1)[3]<-"US_to_Gov_Low"
names(d1)[4]<-"US_to_Gov_High"
names(d1)[5]<-"US_to_Reb"
names(d1)[6]<-"US_to_Reb_Low"
names(d1)[7]<-"US_to_Reb_High"

names(e1)[3]<-"US_to_Gov"
names(e1)[4]<-"US_to_Gov_Low"
names(e1)[5]<-"US_to_Gov_High"
names(e1)[7]<-"US_to_Reb"
names(e1)[8]<-"US_to_Reb_Low"
names(e1)[9]<-"US_to_Reb_High"


gray<-"#d3d3d3";darkgray<-"#808080"


layout(matrix(c(1,2), nrow=2, byrow=TRUE), heights=c(4, 1))
par(mai=c(0.20,0.20,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)
n.ahead<-seq(1,5,by=1)

plot(n.ahead,e$US_to_Reb[1:5],type="n",main="Twitter Effect on US Behavior Toward the Rebels",lwd=4,col="black",ylab=expression(bold(US)~bold(to)~bold(Rebels)),pch=19,ylim=c(min(e$US_to_Reb_Low),max(e$US_to_Reb_High)),xlim=c(1,5),xaxt='n')
abline(h=0,col="black",lwd=1,lty=3)

axis(1,at=c(1,2,3,4,5), labels=c("Total","International Support","Battlefield Success","Denounce Government","Clarify Aims"), main=expression(bold(Twitter)) )
points(n.ahead[1], e$US_to_Reb_Low[5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[1], e$US_to_Reb_High[5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[1], y0=e$US_to_Reb_High[5],x1=n.ahead[1], y1=e$US_to_Reb_Low[5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[1], e1$US_to_Reb_Low[5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[1], e1$US_to_Reb_High[5],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[1], y0=e1$US_to_Reb_High[5],x1=n.ahead[1], y1=e1$US_to_Reb_Low[5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[1], e$US_to_Reb[5],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[2], a$US_to_Reb_Low[5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[2], a$US_to_Reb_High[5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[2], y0=a$US_to_Reb_High[5],x1=n.ahead[2], y1=a$US_to_Reb_Low[5],lwd=2,pch=16, col=darkgray,lty=3)

points(n.ahead[2], a1$US_to_Reb_Low[5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[2], a1$US_to_Reb_High[5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[2], y0=a1$US_to_Reb_High[5],x1=n.ahead[2], y1=a1$US_to_Reb_Low[5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[2], a$US_to_Reb[5],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[3], b$US_to_Reb_Low[5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[3], b$US_to_Reb_High[5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[3], y0=b$US_to_Reb_High[5],x1=n.ahead[3], y1=b$US_to_Reb_Low[5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[3], b1$US_to_Reb_Low[5],lwd=3,pch= 24 , col= gray,lty=3)
points(n.ahead[3], b1$US_to_Reb_High[5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[3], y0=b1$US_to_Reb_High[5],x1=n.ahead[3], y1=b1$US_to_Reb_Low[5],lwd=2,pch=16, col=gray,lty=3)

points(n.ahead[3], b$US_to_Reb[5],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[4],  c$US_to_Reb_Low[5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[4], c$US_to_Reb_High[5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[4], y0=c$US_to_Reb_High[5],x1=n.ahead[4], y1=c$US_to_Reb_Low[5],lwd=2,pch=16, col=darkgray,lty=3)

points(n.ahead[4],  c1$US_to_Reb_Low[5],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[4], c1$US_to_Reb_High[5],lwd=3,pch=25, col=gray,lty=3)
segments(x0=n.ahead[4], y0=c1$US_to_Reb_High[5],x1=n.ahead[4], y1=c1$US_to_Reb_Low[5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[4], c$US_to_Reb[5],lwd=3,pch=19, col= "black",lty=3)

points(n.ahead[5],  d$US_to_Reb_Low[5],lwd=3,pch= 24 , col= darkgray,lty=3)
points(n.ahead[5], d$US_to_Reb_High[5],lwd=3,pch=25, col= darkgray,lty=3)
segments(x0=n.ahead[5], y0=d$US_to_Reb_High[5],x1=n.ahead[5], y1=d$US_to_Reb_Low[5],lwd=2,pch=16, col=darkgray,lty=3)
points(n.ahead[5],  d1$US_to_Reb_Low[5],lwd=3,pch= 24 , col=gray,lty=3)
points(n.ahead[5], d1$US_to_Reb_High[5],lwd=3,pch=25, col= gray,lty=3)
segments(x0=n.ahead[5], y0=d1$US_to_Reb_High[5],x1=n.ahead[5], y1=d1$US_to_Reb_Low[5],lwd=2,pch=16, col=gray,lty=3)
points(n.ahead[5], d$US_to_Reb[5],lwd=3,pch=19, col= "black",lty=3)
plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("IRF","95% C.I.","90% C.I."),box.col="darkgray", col=c("black",darkgray, gray), pch=c(19,25,25),lwd=c(2,3,3))

